package com.tham.dao;

import java.io.IOException;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import oracle.jdbc.OracleTypes;

import org.apache.log4j.Logger;

import utiles.AppProperties;
import utiles.ConexionPool;

import com.fic.dto.CtrlMedicaDTO;
import com.fic.vo.IngHorAcepRechzVO;
import com.tham.dto.ControlDTO;
import com.tham.dto.HoraDisponibleDTO;
import com.tham.dto.HorasBloqueoDTO;
import com.tham.dto.ReservaDTO;
import com.tham.vo.CancelaVO;
import com.tham.vo.ReservaVORA;

public class ControlDAO {
	private static Logger log = Logger.getLogger(ControlDAO.class);
	String pkgVar = (AppProperties.getProperty("aplicacion", "PACKAGE"));

	 public  List<ControlDTO> getCitas(String fecCita, String origen, String paciente, String idPrestacion,String idProfesional, String idArea, String idSede, String canceladas) throws SQLException, IOException{
			//ConexionPool connDao = new ConexionPool();
		 Connection conn = ConexionPool.getConnectionPool();	
	    	//Connection conn = ((javax.sql.PooledConnection)ConexionPool.getConnectionPool()).getConnection();
	    				    
			List<ControlDTO> listCtrlMed = new ArrayList<ControlDTO>();
			try {
				String query = "{ call "+pkgVar+".Pkg_tho_control.getCitas(?,?,?,?,?,?,?,?,?) }"; 	       
				CallableStatement  stmt = conn.prepareCall(query);
				stmt.setString(1, fecCita);
				stmt.setString(2, origen);
				stmt.setString(3, paciente);
				stmt.setString(4, idPrestacion);
				stmt.setString(5, idProfesional);
				stmt.setString(6, idArea);
				stmt.setString(7, idSede);
				stmt.setString(8, canceladas);
				stmt.registerOutParameter(9, OracleTypes.CURSOR);
				stmt.execute();
				ResultSet rs = (ResultSet)stmt.getObject(9);
				while (rs.next()) {
					ControlDTO ctrlMedDTO = new ControlDTO();
					ctrlMedDTO.setIdAgendaReserv(rs.getString(1));
					ctrlMedDTO.setIdAgendaPrg(rs.getString(2));
					ctrlMedDTO.setFecCita(rs.getString(3));
					ctrlMedDTO.setHoraCita(rs.getString(4));
					ctrlMedDTO.setIdPaciente(rs.getString(5));
					ctrlMedDTO.setRutPac(rs.getString(6));
					ctrlMedDTO.setDvRutPac(rs.getString(7));
					ctrlMedDTO.setRutDvPac(rs.getString(8));
					ctrlMedDTO.setPaciente(rs.getString(9));
					ctrlMedDTO.setIdEntidad(rs.getString(10));
					ctrlMedDTO.setEntidad(rs.getString(11));
					ctrlMedDTO.setEntidadNomCorto(rs.getString(12));
					ctrlMedDTO.setIdPrestacion(rs.getString(13));
					ctrlMedDTO.setDescrPrest(rs.getString(14));
					ctrlMedDTO.setAsistenciaSN(rs.getString(15));
					ctrlMedDTO.setHoraAsistencia(rs.getString(16));				
					ctrlMedDTO.setHoraAtencion(rs.getString(17));
					ctrlMedDTO.setRechazoProfAR(rs.getString(18));
					ctrlMedDTO.setConfirmadoSN(rs.getString(19));
					ctrlMedDTO.setCantHorasReserv(rs.getString(20));
					ctrlMedDTO.setIdTipAtenc(rs.getString(21));
					ctrlMedDTO.setDescripcionTipAtenc(rs.getString(22));
					ctrlMedDTO.setTelefPAC(rs.getString(23));
					ctrlMedDTO.setTelefMovPAC(rs.getString(24));
					ctrlMedDTO.setSocial(rs.getString(25));
					ctrlMedDTO.setEstadoAgenda(rs.getString(26));
					ctrlMedDTO.setTiempoEspera(rs.getString(27));
					ctrlMedDTO.setFechaRegistro(rs.getString(28));
					ctrlMedDTO.setIdEspecialidad(rs.getString(29));
					ctrlMedDTO.setIdEstAg(rs.getString(30));
					ctrlMedDTO.setExamen(rs.getString(31));
					ctrlMedDTO.setEdad(rs.getString(32));
					ctrlMedDTO.setObservacion(rs.getString(33));
					ctrlMedDTO.setImgConfirmado(rs.getString(34));
					ctrlMedDTO.setImgAsistencia(rs.getString(35));
					ctrlMedDTO.setImgAtencion(rs.getString(36));
					ctrlMedDTO.setImgAtencion(rs.getString(36));
					ctrlMedDTO.setPrevisionEEG(rs.getString(37));
					//System.out.println("conf:"+ctrlMedDTO.getImgConfirmado());
					listCtrlMed.add(ctrlMedDTO);
				}
				rs.close();
				stmt.close();
			} catch (SQLException ex) {  
				log.error("Error ControlDAO.getCitas SQLException: " +ex.getMessage());
				System.out.println(ex.getMessage());
			} finally {
				//ConexionPool.desconectaPool(conn);
				conn.close();
				conn = null;
			}
			return listCtrlMed;	
		}	

	 public  List<ControlDTO> setCitas(String idReserva, String tipo, String estado, String obser,String idUser) throws SQLException, IOException{
			//ConexionPool connDao = new ConexionPool();
		 Connection conn = ConexionPool.getConnectionPool();	
	    	//Connection conn = ((javax.sql.PooledConnection)ConexionPool.getConnectionPool()).getConnection();
	    				    
			List<ControlDTO> listCtrlMed = new ArrayList<ControlDTO>();
			try {
				String query = "{ call "+pkgVar+".Pkg_tho_control.setCitas(?,?,?,?,?,?) }"; 	       
				CallableStatement  stmt = conn.prepareCall(query);
				stmt.setString(1, idReserva);
				stmt.setString(2, tipo);
				stmt.setString(3, estado);
				stmt.setString(4, obser);
				stmt.setString(5, idUser);
				stmt.registerOutParameter(6, OracleTypes.CURSOR);
				stmt.execute();
				ResultSet rs = (ResultSet)stmt.getObject(6);
				while (rs.next()) {
					ControlDTO ctrlMedDTO = new ControlDTO();
					ctrlMedDTO.setIdAgendaReserv(rs.getString(1));
					listCtrlMed.add(ctrlMedDTO);
				}
				rs.close();
				stmt.close();
				

			} catch (SQLException ex) {  
				log.error("Error ControlDAO.setCitas SQLException: " +ex.getMessage());
				System.out.println(ex.getMessage());
			} finally {
				//ConexionPool.desconectaPool(conn);
				conn.close();
				conn = null;
			}
			return listCtrlMed;	
		}
	 
	 public  List<ReservaDTO> setCancelarHora(CancelaVO cancelVO) throws SQLException, IOException{
			//ConexionPool connDao = new ConexionPool();
		 Connection conn = ConexionPool.getConnectionPool();	
	    	//Connection conn = ((javax.sql.PooledConnection)ConexionPool.getConnectionPool()).getConnection();			    
			List<ReservaDTO> listCtrlMed = new ArrayList<ReservaDTO>();
			try {
				String query = "{ call "+pkgVar+".Pkg_tho_control.setCancelarHora(?,?,?,?,?,?) }"; 	       
				CallableStatement  stmt = conn.prepareCall(query);
				stmt.setString(1, cancelVO.getIdAgendaPrg());
				stmt.setString(2, cancelVO.getIdAgendaReserva());
				stmt.setString(3, cancelVO.getIdMotivo());
				stmt.setString(4, cancelVO.getObservacion());
				stmt.setString(5, cancelVO.getIdUser());
				stmt.registerOutParameter(6, OracleTypes.INTEGER);			
				stmt.execute();
				ReservaDTO ctrlMedDTO = new ReservaDTO();
				ctrlMedDTO.setIdHistorialCancel(stmt.getString(6));
				//System.out.println(stmt.getString(6));
				listCtrlMed.add(ctrlMedDTO);
				stmt.close();
			} catch (SQLException ex) {  
				log.error("Error ControlDAO.setCancelarHora SQLException: " +ex.getMessage());
				System.out.println(ex.getMessage());
			} finally {
				//ConexionPool.desconectaPool(conn);
				conn.close();
				conn = null;
			}
			return listCtrlMed;	
		}
	 
		public  List<HorasBloqueoDTO> updateUrgCita(String idAgProg, String param, String idAgReserv) throws SQLException, IOException{
			Connection conn = ConexionPool.getConnectionPool();	
			List<HorasBloqueoDTO> listCantHrs = new ArrayList<HorasBloqueoDTO>();
			try {
				String query = "{ call "+pkgVar+".Pkg_tho_bloqueo.setUpdateUrgente(?,?,?,?) }"; 	       
				CallableStatement  stmt = conn.prepareCall(query);
				stmt.setString(1, idAgProg);
				stmt.setString(2, param);
				stmt.setString(3, idAgReserv);	
				stmt.registerOutParameter(4, OracleTypes.CURSOR);
				stmt.execute();
				ResultSet rs = (ResultSet)stmt.getObject(4);
				while (rs.next()) {
					HorasBloqueoDTO cantHrs = new HorasBloqueoDTO();
					cantHrs.setHoraAct(rs.getString(1));
				}
				rs.close();
				stmt.close();

			} catch (SQLException ex) {  
				log.error("Error ControlDAO.setBloqHrs SQLException: " +ex.getMessage());
				System.out.println(ex.getMessage());
			} finally {
				//ConexionPool.desconectaPool(conn);
				conn.close();
				conn = null;
			}
			return listCantHrs;		
		}	
		 public List<ControlDTO> getBloqueos(String idDoctor) throws SQLException, IOException{
			 	
			 Connection conn = ConexionPool.getConnectionPool();	    
				List<ControlDTO> listCtrlMed = new ArrayList<ControlDTO>();
				try {
					String query = "{ call "+pkgVar+".Pkg_tho_control.getBloqueos(?,?) }"; 	       
					CallableStatement  stmt = conn.prepareCall(query);
					stmt.setString(1, idDoctor);		
					stmt.registerOutParameter(2, OracleTypes.CURSOR);
					stmt.execute();
					ResultSet rs = (ResultSet)stmt.getObject(2);
					while (rs.next()) {
						ControlDTO ctrlMedDTO = new ControlDTO();
						ctrlMedDTO.setIdAgendaReserv(rs.getString(1));
						ctrlMedDTO.setIdAgendaPrg(rs.getString(2));
						ctrlMedDTO.setFecCita(rs.getString(3));
						ctrlMedDTO.setHoraCita(rs.getString(4));
						ctrlMedDTO.setIdPaciente(rs.getString(5));
						ctrlMedDTO.setRutDvPac(rs.getString(6));
						ctrlMedDTO.setPaciente(rs.getString(7));
						ctrlMedDTO.setTelefPAC(rs.getString(8));
						ctrlMedDTO.setTelefMovPAC(rs.getString(9));
						ctrlMedDTO.setSocial(rs.getString(10));
						ctrlMedDTO.setIdEspecialidad(rs.getString(11));
						ctrlMedDTO.setIdPrestacion(rs.getString(12));
						ctrlMedDTO.setIdEntidad(rs.getString(13));
						ctrlMedDTO.setIdTipAtenc(rs.getString(14));
						ctrlMedDTO.setDescripcionTipAtenc(rs.getString(15));
						ctrlMedDTO.setCantHorasReserv(rs.getString(16));
						ctrlMedDTO.setRutPac(rs.getString(17));
						ctrlMedDTO.setDvRutPac(rs.getString(18));
						listCtrlMed.add(ctrlMedDTO);
					}
					rs.close();
					stmt.close();
				} catch (SQLException ex) {  
					log.error("Error ControlDAO.getBloqueos SQLException: " +ex.getMessage());
					System.out.println(ex.getMessage());
				} finally {
					//ConexionPool.desconectaPool(conn);
					conn.close();
					conn = null;
				}
				return listCtrlMed;	
			}	
			public List<HoraDisponibleDTO> setAgendaReservaRA(ReservaVORA resVO) throws SQLException, IOException{
				//ConexionPool connDao = new ConexionPool();
				/*kSystem.out.println("prg "+resVO.getIdAgendaPrg()+" pac:"+resVO.getIdPaciente()+" cant:"+
						resVO.getCantHoras()+" urg:"+resVO.getUrgenteSN()+" tipo:"+resVO.getIdTipoPac()+" user:"+resVO.getIdUser()+" ser:"+
						resVO.getIdServicio()+" obs:"+resVO.getObservacion()+" conf:"+resVO.getConfReag());*/

				Connection conn = ConexionPool.getConnectionPool();	
		    	//Connection conn = ((javax.sql.PooledConnection)ConexionPool.getConnectionPool()).getConnection();
		    						    
				int idMovimiento = 0;
				int cancelado = 0;				

				List<HoraDisponibleDTO> listAgenda = new ArrayList<HoraDisponibleDTO>();
				try {
					String query = "{ call "+pkgVar+".PKG_THO_RESERVA.setInsertAgendaReservBloq(?,?,?,?,?,?,?,?,?,?) }"; 	       
					CallableStatement  stmt = conn.prepareCall(query);
					stmt.setString(1, resVO.getIdAgendaPrg());
					stmt.setString(2, resVO.getIdPaciente());
					stmt.setString(3, resVO.getCantHoras());
					stmt.setString(4, resVO.getUrgenteSN());
					stmt.setString(5, resVO.getIdTipoPac());
					stmt.setString(6, resVO.getIdUser());
					stmt.setString(7, resVO.getIdServicio());           
					stmt.setString(8, resVO.getObservacion());
					//stmt.setString(9, "");
					stmt.setString(9, resVO.getIdAgReserv());
					stmt.registerOutParameter(10, OracleTypes.INTEGER);
					stmt.execute();
					HoraDisponibleDTO agenReservDTO = new HoraDisponibleDTO();
					idMovimiento = (stmt.getInt(10));
					agenReservDTO.setIdAgendaReserva(String.valueOf(idMovimiento));
					listAgenda.add(agenReservDTO);
					stmt.close();
				} catch (SQLException ex) {  
					log.error("Error ControlDAO.setInsertAgendaReservBloq SQLException: " +ex.getMessage());
					System.out.println(ex.getMessage());
				} finally {
					//ConexionPool.desconectaPool(conn);
					conn.close();
					conn = null;
				}
				return listAgenda;
			}		
			
			 public int getCantBloqueos(String idArea) throws SQLException, IOException{
				 	
				 Connection conn = ConexionPool.getConnectionPool();	    
					int cantidad=0;
					try {
						String query = "{ call "+pkgVar+".Pkg_tho_control.getCantBloqueos(?,?) }"; 	       
						CallableStatement  stmt = conn.prepareCall(query);
						stmt.setString(1, idArea);
						stmt.registerOutParameter(2, OracleTypes.NUMBER);
						stmt.execute();
						cantidad = stmt.getInt(2);
						stmt.close();
					} catch (SQLException ex) {  
						log.error("Error ControlDAO.getCantBloqueos SQLException: " +ex.getMessage());
						System.out.println(ex.getMessage());
					} finally {
						//ConexionPool.desconectaPool(conn);
						conn.close();
						conn = null;
					}
					return cantidad;	
				}	
			 
			 public void setAcepRechzPAC(IngHorAcepRechzVO ingHorAcepRechzVO) throws SQLException, IOException{
					 Connection conn = ConexionPool.getConnectionPool();	    
							try {
								String query = "{ call "+pkgVar+".Pkg_tho_control.setAcepRechzPAC(?,?,?,?) }";				
								CallableStatement  stmt = conn.prepareCall(query);
								stmt.setString(1, ingHorAcepRechzVO.getIdAgendaReserv());
								stmt.setString(2, ingHorAcepRechzVO.getHoraAceptRechazo());
								stmt.setString(3, ingHorAcepRechzVO.getAcepProfAR());
								stmt.setString(4, ingHorAcepRechzVO.getUserAct());										
								stmt.execute();
								stmt.close();
							} catch (SQLException ex) {  
								log.error("Error ControlDAO.setAcepRechzPAC SQLException: " +ex.getMessage());
								System.out.println(ex.getMessage());				
							} finally {
								conn.close();
								conn = null;						
								log.info("Se ingresa aceptacion de paciente idAgendaReserv :"+ ingHorAcepRechzVO.getIdAgendaReserv());						
							}						
							
				}
			 
			 public List<CtrlMedicaDTO> getCtrlMedByFecCitaPeAndIdProf(String fecCita, String idProf) throws SQLException, IOException{
				 	Connection conn = ConexionPool.getConnectionPool();		    
					List<CtrlMedicaDTO> listCtrlMed = new ArrayList<CtrlMedicaDTO>();
					try {
						String query = "{ call "+pkgVar+".Pkg_tho_control.getCtrlMedByFecCitaPeAndIdProf(?,?,?) }"; 	       
						CallableStatement  stmt = conn.prepareCall(query);
						stmt.setString(1, fecCita);
						stmt.setString(2, idProf);
						stmt.registerOutParameter(3, OracleTypes.CURSOR);
						stmt.execute();
						ResultSet rs = (ResultSet)stmt.getObject(3);
						while (rs.next()) {
							CtrlMedicaDTO ctrlMedDTO = new CtrlMedicaDTO();
							ctrlMedDTO.setIdAgendaReserv(rs.getString(1));
							ctrlMedDTO.setIdAgendaPrg(rs.getString(2));
							ctrlMedDTO.setFecCita(rs.getString(3));
							ctrlMedDTO.setHoraCita(rs.getString(4));
							ctrlMedDTO.setIdPaciente(rs.getString(5));
							ctrlMedDTO.setRutPac(rs.getString(6));
							ctrlMedDTO.setDvRutPac(rs.getString(7));
							ctrlMedDTO.setNombrePac(rs.getString(8));
							ctrlMedDTO.setApellPatPac(rs.getString(9));
							ctrlMedDTO.setApellMatPac(rs.getString(10));
							ctrlMedDTO.setIdProfesional(rs.getString(11));
							ctrlMedDTO.setNombreProf(rs.getString(12));
							ctrlMedDTO.setApellPatProf(rs.getString(13));
							ctrlMedDTO.setApellMatProf(rs.getString(14));		
							ctrlMedDTO.setIdPrestacion(rs.getString(15));
							ctrlMedDTO.setDescrPrest(rs.getString(16));
							ctrlMedDTO.setAsistenciaSN(rs.getString(17));
							ctrlMedDTO.setHoraAasistencia(rs.getString(18));				
							ctrlMedDTO.setHoraAtencion(rs.getString(19));
							ctrlMedDTO.setRechazoProfAR(rs.getString(20));
							ctrlMedDTO.setConfirmadoSN(rs.getString(21));
							ctrlMedDTO.setCantHorasReserv(rs.getString(22));
							ctrlMedDTO.setIdTipAtenc(rs.getString(23));
							ctrlMedDTO.setDescripcionTipAtenc(rs.getString(24));
							ctrlMedDTO.setTelefPAC(rs.getString(25));
							ctrlMedDTO.setTelefMovPAC(rs.getString(26));
							ctrlMedDTO.setSocial(rs.getString(27));
							ctrlMedDTO.setEstadoAgenda(rs.getString(28));
							ctrlMedDTO.setTiempoEspera(rs.getString(29));				
							listCtrlMed.add(ctrlMedDTO);
						}
						rs.close();
						stmt.close();
					} catch (SQLException ex) {  
						log.error("Error ControlDAO.getCtrlMedByFecCitaPeAndIdProf SQLException: " +ex.getMessage());
						System.out.println(ex.getMessage());
					} finally {
						conn.close();
						conn = null;
					}
					return listCtrlMed;	
				}	
			 
			 public List<CtrlMedicaDTO> getCtrlMedByFecCitaAndIdProf(String fecCita, String idProf) throws SQLException, IOException{
				 	Connection conn = ConexionPool.getConnectionPool();	    
					List<CtrlMedicaDTO> listCtrlMed = new ArrayList<CtrlMedicaDTO>();
					try {
						String query = "{ call "+pkgVar+".Pkg_tho_control_reserv.getCtrlMedByFecCitaAndIdProf(?,?,?) }"; 	       
						CallableStatement  stmt = conn.prepareCall(query);
						stmt.setString(1, fecCita);
						stmt.setString(2, idProf);
						stmt.registerOutParameter(3, OracleTypes.CURSOR);
						stmt.execute();
						ResultSet rs = (ResultSet)stmt.getObject(3);
						while (rs.next()) {
							CtrlMedicaDTO ctrlMedDTO = new CtrlMedicaDTO();
							ctrlMedDTO.setIdAgendaReserv(rs.getString(1));
							ctrlMedDTO.setIdAgendaPrg(rs.getString(2));
							ctrlMedDTO.setFecCita(rs.getString(3));
							ctrlMedDTO.setHoraCita(rs.getString(4));
							ctrlMedDTO.setIdPaciente(rs.getString(5));
							ctrlMedDTO.setRutPac(rs.getString(6));
							ctrlMedDTO.setDvRutPac(rs.getString(7));
							ctrlMedDTO.setNombrePac(rs.getString(8));
							ctrlMedDTO.setApellPatPac(rs.getString(9));
							ctrlMedDTO.setApellMatPac(rs.getString(10));
							ctrlMedDTO.setIdProfesional(rs.getString(11));
							ctrlMedDTO.setNombreProf(rs.getString(12));
							ctrlMedDTO.setApellPatProf(rs.getString(13));
							ctrlMedDTO.setApellMatProf(rs.getString(14));		
							ctrlMedDTO.setIdPrestacion(rs.getString(15));
							ctrlMedDTO.setDescrPrest(rs.getString(16));
							ctrlMedDTO.setAsistenciaSN(rs.getString(17));
							ctrlMedDTO.setHoraAasistencia(rs.getString(18));				
							ctrlMedDTO.setHoraAtencion(rs.getString(19));
							ctrlMedDTO.setRechazoProfAR(rs.getString(20));
							ctrlMedDTO.setConfirmadoSN(rs.getString(21));
							ctrlMedDTO.setCantHorasReserv(rs.getString(22));
							ctrlMedDTO.setIdTipAtenc(rs.getString(23));
							ctrlMedDTO.setDescripcionTipAtenc(rs.getString(24));
							ctrlMedDTO.setTelefPAC(rs.getString(25));
							ctrlMedDTO.setTelefMovPAC(rs.getString(26));
							ctrlMedDTO.setSocial(rs.getString(27));
							ctrlMedDTO.setEstadoAgenda(rs.getString(28));
							ctrlMedDTO.setTiempoEspera(rs.getString(29));		
							ctrlMedDTO.setFechaRegistro(rs.getString(29));
							listCtrlMed.add(ctrlMedDTO);
						}
						rs.close();
						stmt.close();
					} catch (SQLException ex) {  
						log.error("Error ControlDAO.getCtrlMedByFecCitaAndIdProf SQLException: " +ex.getMessage());
						System.out.println(ex.getMessage());
					} finally {
						conn.close();
						conn = null;
					}
					return listCtrlMed;	
				}			 

			 public List<CtrlMedicaDTO> getControlMedByFecCita(String fecCita, String origen) throws SQLException, IOException{
				 	Connection conn = ConexionPool.getConnectionPool();			    
					List<CtrlMedicaDTO> listCtrlMed = new ArrayList<CtrlMedicaDTO>();
					try {
						String query = "{ call "+pkgVar+".Pkg_tho_control.getControlMedByFecCita(?,?,?) }"; 	       
						CallableStatement  stmt = conn.prepareCall(query);
						stmt.setString(1, fecCita);
						stmt.setString(2, origen);	
						stmt.registerOutParameter(3, OracleTypes.CURSOR);
						stmt.execute();
						ResultSet rs = (ResultSet)stmt.getObject(3);
						while (rs.next()) {
							CtrlMedicaDTO ctrlMedDTO = new CtrlMedicaDTO();
							ctrlMedDTO.setIdAgendaReserv(rs.getString(1));
							ctrlMedDTO.setIdAgendaPrg(rs.getString(2));
							ctrlMedDTO.setFecCita(rs.getString(3));
							ctrlMedDTO.setHoraCita(rs.getString(4));
							ctrlMedDTO.setIdPaciente(rs.getString(5));
							ctrlMedDTO.setRutPac(rs.getString(6));
							ctrlMedDTO.setDvRutPac(rs.getString(7));
							ctrlMedDTO.setNombrePac(rs.getString(8));
							ctrlMedDTO.setApellPatPac(rs.getString(9));
							ctrlMedDTO.setApellMatPac(rs.getString(10));
							ctrlMedDTO.setIdProfesional(rs.getString(11));
							ctrlMedDTO.setNombreProf(rs.getString(12));
							ctrlMedDTO.setApellPatProf(rs.getString(13));
							ctrlMedDTO.setApellMatProf(rs.getString(14));		
							ctrlMedDTO.setIdPrestacion(rs.getString(15));
							ctrlMedDTO.setDescrPrest(rs.getString(16));
							ctrlMedDTO.setAsistenciaSN(rs.getString(17));
							ctrlMedDTO.setHoraAasistencia(rs.getString(18));				
							ctrlMedDTO.setHoraAtencion(rs.getString(19));
							ctrlMedDTO.setRechazoProfAR(rs.getString(20));
							ctrlMedDTO.setConfirmadoSN(rs.getString(21));
							ctrlMedDTO.setCantHorasReserv(rs.getString(22));
							ctrlMedDTO.setIdTipAtenc(rs.getString(23));
							ctrlMedDTO.setDescripcionTipAtenc(rs.getString(24));
							ctrlMedDTO.setTelefPAC(rs.getString(25));
							ctrlMedDTO.setTelefMovPAC(rs.getString(26));
							ctrlMedDTO.setSocial(rs.getString(27));
							ctrlMedDTO.setEstadoAgenda(rs.getString(28));
							ctrlMedDTO.setTiempoEspera(rs.getString(29));	
							ctrlMedDTO.setIdEstAg(rs.getString(30));
							listCtrlMed.add(ctrlMedDTO);
						}
						rs.close();
						stmt.close();
					} catch (SQLException ex) {  
						log.error("Error ControlDAO.getControlMedByFecCita SQLException: " +ex.getMessage());
						System.out.println(ex.getMessage());
					} finally {
						conn.close();
						conn = null;
					}
					return listCtrlMed;	
				}			 
			 
			 public int setRecuperaCita(String idAgendaReservada) throws SQLException, IOException{
				 Connection conn = ConexionPool.getConnectionPool();
				 int retorno=0;
						try {
							String query = "{ call "+pkgVar+".Pkg_tho_control.setRecuperaCita(?,?) }";				
							CallableStatement  stmt = conn.prepareCall(query);
							stmt.setString(1, idAgendaReservada);																	
							stmt.registerOutParameter(2, OracleTypes.INTEGER);
							stmt.execute();
							retorno = (stmt.getInt(2));
						} catch (SQLException ex) {  
							log.error("Error ControlDAO.setRecuperaCita SQLException: " +ex.getMessage());
							System.out.println(ex.getMessage());				
						} finally {
							conn.close();
							conn = null;												
						}	
						return retorno;
						
			}			 
			 
}
